/**
 *
 * @description:
 * @author:junyong.hong
 * @createTime:2017/12/7
 * @version:1.0.0.0
 * @history:
 *    1、
 *    2、
 *
 */
define([
    'app',
], function (app) {
    'use strict';
    app.controller('dashboard.controller', ['$scope', '$state', '$translate', '$window', '$timeout', function ($scope, $state, $translate, $window, $timeout) {
        var vm = this;

        vm.changeLanguage = function (langKey) {
            $timeout(function () { // 解决静态文本已经翻译，页面却没有及时刷新问题
                $translate.use(langKey);
            }, 500);
        }

        vm.inputValue = ''
        $scope.$watch('vm.inputValue', function (newValue, oldValue) {
            var len = 8
            var num = 0;
            var result;
            for (var i = 0; i < newValue.length; i++) {
                var a = newValue.charAt(i);
                if (/^[\u4e00-\u9fa5]+$/i.test(a)) {
                    num += 2;
                } else {
                    num += 1;
                }
                if (num <= len) {
                    result = newValue.substring(0, i + 1);
                    vm.inputValue = result;
                }
            }
        })
    }]);


});